import sys
# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()

name = 'scr'
format = 'png'

if (len(sys.argv) > 1):
    name = sys.argv[1]

garbage = ''
number = 0

while(1):
    garbage = raw_input('press Enter to take screenshit, or q to quit:')
    if(garbage == 'q'):
        break

    number = number + 1
    strnum = "%02d" % (number,)
    filename = name+strnum+'.'+format

    # Takes a screenshot
    result = device.takeSnapshot()

    # Writes the screenshot to a file
    result.writeToFile(filename,format)


    print "wrote "+filename

